package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yamanyar.weebill.domain.Attachment;
import com.yamanyar.weebill.service.AttachmentService;

/**
 * Creates an Attachment. Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@Component("createAttachment")
@Scope("request")
public class CreateAttachment implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private AttachmentService attachmentService;

	private Attachment attachment = new Attachment();

	@Autowired
	public CreateAttachment(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}

	public String save() {
		attachmentService.createNew(attachment);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO, "Attachment is saved successfully",
				"OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		attachment = new Attachment();
		return null;
	}

	public Attachment getAttachment() {
		return attachment;
	}

	public void setAttachment(Attachment attachment) {
		this.attachment = attachment;
	}
}
